package com.fay.basic.base.copy.test;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.DigestUtils;

import java.util.Map;
import java.util.UUID;

/**
 * @Title:
 * @Description:
 * @Author Fay Wang
 * @Date 2019/6/23 12:31
 * @Version 1.0
 */
public class CommunityUtil {

    public static String generateUUID() {
        return UUID.randomUUID().toString();
    }

    public static String md5(String key) {
        if (StringUtils.isBlank(key)) {
            return null;
        }
        return DigestUtils.md5DigestAsHex(key.getBytes());
    }

    public static String getJSONString(int code, String msg, Map<String, Object> map) {
        JSONObject json = new JSONObject();
        json.put("code", code);
        json.put("msg", msg);
        if (map != null) {
            for (String key : map.keySet()) {
                json.put(key, map.get(key));
            }
        }
        return json.toJSONString();
    }

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            String old = CommunityUtil.generateUUID();
            String news = old.replace("-", "");
            System.out.println("old: " + old + "new: " + news);
        }
    }
}
